﻿Imports System.Data.OleDb
Partial Public Class UserProfileShow
    Inherits System.Web.UI.Page
    Dim LogedINUid As Int16 = 0
    Dim LoadedUserName As String
    Dim LoadedUsersID As String

    Sub Load_UserDetails()

        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        Try
            con.Open()

            Dim oledbcmd As New OleDbCommand("SELECT * From UserDetails where UserName ='" + findUSerName() + "'", con)
            Dim dr As OleDbDataReader = oledbcmd.ExecuteReader()
            While dr.Read()
                Me.lbl_UserName.Text = dr("UserName")
                Me.lbl_Age.Text = dr("Age")
                Me.lbl_gender.Text = dr("Gender")
                Me.lbl_city.Text = dr("City")
                Me.lbl_postcode.Text = dr("PostCode")
                Me.img_User.ImageUrl = dr("Photo")



            End While
        Catch ex As Exception

        End Try
        con.Close()
    End Sub

    Function findUSerID()
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        con.Open()

        Dim oledbcmd As New OleDbCommand("SELECT * From aspnet_Users where UserName = @Username", con)
        oledbcmd.Parameters.AddWithValue("@Username", User.Identity.Name)
        Dim dr As OleDbDataReader = oledbcmd.ExecuteReader()
        dr.Read()
        LogedINUid = dr("UserId")
        Return LogedINUid
    End Function

    Function findUSerName()
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        con.Open()

        Dim oledbcmd As New OleDbCommand("SELECT * From aspnet_Users where UserID = @UserID", con)
        oledbcmd.Parameters.AddWithValue("@UserID", Request.QueryString("ID"))
        Dim dr As OleDbDataReader = oledbcmd.ExecuteReader()
        dr.Read()
        LoadedUserName = dr("UserName")
        Return LoadedUserName
    End Function


    Sub insert_visitor_details()
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        con.Open()

        Dim oledbcmd As New OleDbCommand("INSERT INTO RecentVisitors (UserID,VisitorID,TimeOfVisit,DateOfVisit,NameOfVisitor) values (@UserID,VisitorID,TimeOfVisit,DateOfVisit,NameOfVisitor)", con)
        oledbcmd.Parameters.AddWithValue("@UserID", Request.QueryString("ID"))
        oledbcmd.Parameters.AddWithValue("@VisitorID", findUSerID())
        oledbcmd.Parameters.AddWithValue("@TimeOfVisit", Date.Now.ToShortTimeString())
        oledbcmd.Parameters.AddWithValue("@DateOfVisit", Date.Now.ToShortDateString())
        oledbcmd.Parameters.AddWithValue("@NameOfVisitor", User.Identity.Name)
        oledbcmd.ExecuteNonQuery()
    End Sub

  
    Private Sub UserProfileShow_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Load_UserDetails()
        insert_visitor_details()
    End Sub
End Class